import {BrowserWindow} from 'electron'
import * as electron from "electron"
import {createProtocol} from "_vue-cli-plugin-electron-builder@2.1.1@vue-cli-plugin-electron-builder/lib";

let LoginWin = null

// 通过关键字export进行导出.
export async function createLoginWindow() {
    // Create the browser window.
    const Menu = electron.Menu
    // 渲染进程.
    const win = new BrowserWindow({
        width: 280,
        height: 380,
        title: "简聊",
        // frame: false,
        webPreferences: {
            // Use pluginOptions.nodeIntegration, leave this alone
            // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
            nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
            contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION
        }
    })

    LoginWin = win
    // 设置菜单导航栏为nil.
    Menu.setApplicationMenu(null)
    if (process.env.WEBPACK_DEV_SERVER_URL) {
        // Load the url of the dev server if in development mode
        // await 暂停diamante在该行上，知道promise完成，然后返回结果，再继续执行await。
        await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
        if (!process.env.IS_TEST) win.webContents.openDevTools()
    } else {
        createProtocol('app')
        // 在Windows窗口加载html文件,而html文件的渲染由Vue来进行渲染.
        // 登录的HTML单独使用.
        win.loadURL('../../public/index.html')
    }
}

export {LoginWin}